package com.example.demo.controller;

import com.example.demo.entity.Commodity;
import com.example.demo.mapper.CommodityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class Basic {

    @Autowired
    private CommodityMapper commodityMapper;

    // 进入首页
    @GetMapping(value = "/index.html")
    public String indexHtml()
    {
        return "index";
    }

    @GetMapping(value = "/address.html")
    public String addressHtml()
    {
        return "add_address";
    }

    @GetMapping(value = "/shop.html")
    public String shopHtml(String options ,  Model model)
    {
        model.addAttribute("options",options);
        List<Commodity> commodities = commodityMapper.selectList(null);
        // 获取列表
        model.addAttribute("commodities",commodities);
        return "shop";
    }

}
